package Exam2.exam1;

import java.util.Random;

public class Exam1 {
    Random random = new Random();


    public void setArray(int array[][]) {//创建数组

        for (int i = 0; i < array.length; i++) {//遍历数组的行
            for (int j = 0; j < array.length; j++) {//遍历数组的列
                array[i][j] = random.nextInt(100) + 1;//给数组的变量赋值1~100的随机数
            }
        }
    }

    public void showArray( int array[][]) {//显示数组
        System.out.println("原数组为：");
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array.length; j++) {
                System.out.print(array[i][j] + "\t");
            }
            System.out.println();
        }
    }

    public void addLine( int array[][]) {//行累加
        int sum = 0;
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array.length; j++) {
                sum += array[i][j];
            }
            System.out.printf("第%d的行累加和为%d", i + 1, sum);//打印出每一行的累加和
            sum = 0;
            System.out.println();

        }
    }
        public void addRow(int array[][]) {//列累加
            int sum = 0;
            for (int i = 0; i < array.length; i++) {
                for (int j = 0; j < array.length; j++) {
                    sum += array[j][i];
                }
                System.out.printf("第%d列的累加和为%d",i+1,sum);//打印出每一列的累加和
                sum=0;
                System.out.println();

            }

    }
    public void addXie(int array[][]) {//对角线累加
        int sum = 0;
        for (int i = 0; i < array.length; i++) {//左下累加
            sum+=array[i][i];
        }
        for (int i = array.length-1,j =0; i >=0&&j< array.length; i--,j++) {//右下累加
            sum+=array[j][i];
        }
        System.out.printf("斜对角的累加和为%d",sum);//打印出斜对角线的累加和
    }
}


